package de.kai_morich.simple_usb_terminal;
import android.graphics.RectF;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.fragment.app.FragmentActivity;
import cn.com.zt.camera.controller.CameraControllerImpl;
import cn.com.zt.camera.listener.CodeAnalysisCallback;
import cn.com.zt.camera.view.PreviewLayout;

import java.util.ArrayList;
/**
 * @author : liujiacheng
 * @Date ：2025/7/10 14:50
 * @Description ：
 **/
public class ScanActivity extends FragmentActivity {
    private PreviewLayout previewLayout; // 假设布局中使用FrameLayout作为预览容器
    private final CameraControllerImpl controller = new CameraControllerImpl();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scan_activity); // 使用布局资源ID

        // 手动绑定视图
        previewLayout = findViewById(R.id.previewLayout);

        previewLayout.bindToLifecycle(this); // 需确保布局有实现该方法
        controller.bindCameraPreview(previewLayout);
        controller.startPreview();

        controller.startScan(new CodeAnalysisCallback() {
            @Override
            public void onCodeAnalysisSuccess(ArrayList<String> resultList, ArrayList<RectF> rectList, int imageWidth, int imageHeight) {
                for (String result : resultList) {
                    Toast.makeText(ScanActivity.this, result, Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onCodeAnalysisFail(Exception fail) {
                // 处理失败
            }

            @Override
            public void onCodeAnalysisComplete() {
                // 扫描完成
            }
        });
    }
}